package com.xyz.aclservice.controller;

import com.alibaba.fastjson.JSONObject;

import com.xyz.aclservice.service.EduIndexService;
import com.xyz.entity.R;
import com.xyz.entity.SecurityUser;
import com.xyz.frame.security.api.util.SecurityUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


//@Schema(description="后台首页管理接口")
@Schema(description="后台首页管理接口")
@RestController
@RequestMapping("/admin/acl/index")
@CrossOrigin
public class EduIndexController {

    @Autowired
    private EduIndexService eduIndexService;

    /**
     * 根据token获取用户信息
     */
    @GetMapping("info")
    public R info(){
        //获取当前登录用户用户名
//        String username = SecurityContextHolder.getContext().getAuthentication().getName();
        String userId = SecurityUtils.getUser().getUserId();

        Map<String, Object> userInfo = eduIndexService.getUserInfo(userId);
        return R.ok().data(userInfo);
    }

    /**
     * 获取菜单
     * @return
     */
    @GetMapping("menu")
    public R getMenu(){
        //获取当前登录用户用户名
//        String username = SecurityContextHolder.getContext().getAuthentication().getName();
        String userId = SecurityUtils.getUser().getUserId();
        List<JSONObject> permissionList = eduIndexService.getMenu(userId);
        return R.ok().data("permissionList", permissionList);
    }

    @PostMapping("logout")
    public R logout(){
        return R.ok();
    }

}
